package com.kfm.hotel.controller;

import com.kfm.hotel.util.R;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

@ControllerAdvice
@ResponseBody
public class MyExceptionAdvice {

    @ExceptionHandler(Exception.class)
    public ModelAndView index(Exception exception){
        exception.printStackTrace();
        ModelAndView error = new ModelAndView("error");
        error.addObject("msg", exception.getMessage());
        return error;
    }

    @ExceptionHandler(RuntimeException.class)
    public R runtimeException(RuntimeException exception){
        exception.printStackTrace();
        return R.fail(exception.getMessage());
    }
}
